package com.help10000.rms.ui.adapter

import android.content.Context
import android.widget.ImageView
import com.amir.common.api.ApiContents
import com.amir.common.holder.CommonViewHolder
import com.amir.common.mvp.base.BaseSingleItemTypeRecyclerViewAdapter
import com.amir.common.utils.DisplayUtil
import com.amir.common.utils.ImageHelper
import com.amir.common.weight.DuplicateClickProxy
import com.help10000.rms.R
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.util.SmartGlideImageLoader


class OrderPhotoItemAdapter(context: Context?, dataList: List<String>, resId: Int) :
    BaseSingleItemTypeRecyclerViewAdapter<String>(context, dataList, resId) {
    var itemHeight = 0

    init {
        itemHeight = (DisplayUtil.getDensityWdith(context) - DisplayUtil.dip2px(context, 70f)) / 4
    }


    override fun bindData(holder: CommonViewHolder, data: String, position: Int) {
        var layoutParams = holder.itemView.layoutParams
        layoutParams.height = itemHeight
        holder.itemView.layoutParams = layoutParams

        var imgThumb = holder.getView<ImageView>(R.id.thumbImageView)
        ImageHelper.displayImage(mContext, ApiContents.ImageUrl + data, imgThumb)
        imgThumb.setOnClickListener(DuplicateClickProxy {
            var data = mutableListOf<Any>()
            dataList.forEach { item ->
                data.add(ApiContents.ImageUrl + item)
            }
            XPopup.Builder(mContext)
                .asImageViewer(
                    imgThumb,
                    position,
                    data,
                    null,
                    SmartGlideImageLoader()
                )
                .show()
//            XPopup.Builder(mContext)
//                .dismissOnTouchOutside(true)
//                .asCustom(ViewBigImageDialog(mContext, ApiContents.ImageUrl + data))
//                .show()
        })
    }


}
